﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Skynet
{
    public partial class WordEditor : Form
    {
        public WordEditor()
        {
            InitializeComponent();
        }

        private void WordEditor_Load(object sender, EventArgs e)
        {
            // fill the grids
            this.ucSyn1.pf = (frmSkynet) (this.Tag);
            
            foreach (Word word in ((frmSkynet)(this.Tag)).words.wordList)
            {
                this.ucSyn1.words.wordList.Add(word);
            }
            foreach (Syn syn in ((frmSkynet)(this.Tag)).words.synList)
            {
                this.ucSyn1.words.synList.Add(syn);
            }
            //words

            ucSyn1.dgvWord.Rows.Clear();
            foreach (Word  word in this.ucSyn1.words.wordList)
            {
                ucSyn1.dgvWord.Rows.Add(word.Row);
            }

            //syn

            ucSyn1.dgvSyn.Rows.Clear();
            if (ucSyn1.dgvWord.Rows[0] != null)
            {
                foreach (Syn value in this.ucSyn1.words.synList)
                {
                    if (value.domainRow == ucSyn1.dgvWord.Rows[0])
                    {
                        ucSyn1.dgvSyn.Rows.Add(value.Row);
                    }

                }
            }
        }

        private void WordEditor_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (!ucSyn1.qqqq)
            {
                var dr = MessageBox.Show("Сохранить изменения", "Вопрос",
                                         MessageBoxButtons.YesNo,
                                         MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
                if (dr == DialogResult.Yes)
                {
                    ucSyn1.pf.words = ucSyn1.words;
                }
            }

        }

    
    }
}
